import java.io.InputStream;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import bean.Book;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Main {

	public static void main(String[] args) throws Exception {

		ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());

		// 反序列化时忽略不存在的JavaBean属性:
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

		InputStream input = Main.class.getResourceAsStream("/book.json");
		Book book = mapper.readValue(input, Book.class);

		log.info(book.toString());

		// 序列化为JSON:
		String json = mapper.writeValueAsString(book);
		System.out.println(json);
	}
}
